from pymysql import *
import random
import time


class scan_fun():
    def __init__(self):
        self.scan_rmc_table = 'scan_rmc'
        self.scan_y1sqii_table = 'scan_y1sqii'
        self.now_time = time.strftime("%Y-%m-%d %X", time.localtime())
        self.conn = connect(host='10.10.1.1', user='ly', password='123', port=3306, db='ocr')
        self.cursor = self.conn.cursor(cursor=cursors.DictCursor)  # 查询结果以字典方式返回
        self.insert_data(self.scan_y1sqii_table)


    def insert_data(self, table_obj):
        try:
            if table_obj == 'scan_rmc':
                sql = ''' insert into {} values{} '''.format(table_obj, (random.randint(100, 10000), "789", self.now_time))
            else:
                sql = ''' insert into {} values{} '''.format(table_obj, ((random.randint(100, 10000), self.now_time)))
            print("执行>>>", sql)
            self.cursor.execute(sql)
            self.conn.commit()
        except Exception as e:
            self.conn.rollback()
            print(e)

obj = scan_fun()
